#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# 根据xml文件创建UI类
import sys,time
import codecs

from PyQt5.QtWidgets import (QApplication, QButtonGroup, QRadioButton, QCheckBox, QComboBox,QTabWidget,QMessageBox,QTextEdit,QFrame,QAction,
                             QWidget, QLineEdit, QLabel, QPushButton, QFileDialog, QHBoxLayout, QGridLayout, QVBoxLayout, QListView)
from PyQt5.QtCore import Qt, QTimer, QBasicTimer, QDate, QAbstractListModel, QStringListModel, QEvent,pyqtSignal,QObject
from PyQt5.QtGui import QPixmap,QColor,QIcon,QMouseEvent

from base.CommonWin import BaseTabWin
#from configUtils import * #在 TabXMLToTS  SettingWin都已经import了 这里不需要再次导入
from TabXMLToTS import *  
from SettingWin import *
from ExcelToJson import *
from SheetFieldToStr import *
from configUtils import *

class MyMainWin(BaseTabWin):
    def __init__(self, sizeW=867, sizeH=500, icoUrl='assets/ico/logo.png'):
        super().__init__([TabXMLToTS,SheetFieldToStr], "XML->TS,导表字段", "JoyTools", sizeW, sizeH, icoUrl)      
        #定义菜单动作
        settingAction = QAction(QIcon('assets/ico/logo.png'),'&设置',self)
        settingAction.setShortcut('ctrl+r')
        settingAction.setStatusTip('打开软件设置')
        settingAction.triggered.connect(self.openSetWin)
        
        descAction = QAction(QIcon('assets/ico/logo.png'),'&说明',self)
        #aboutAction.setShortcut('ctrl+r')
        descAction.setStatusTip('软件说明')
        descAction.triggered.connect(self.openDescWin)

        aboutAction = QAction(QIcon('assets/ico/logo.png'),'&关于',self)
        #aboutAction.setShortcut('ctrl+r')
        aboutAction.setStatusTip('软件版本信息')
        aboutAction.triggered.connect(self.openAboutWin)        

        importAction = QAction(QIcon('assets/ico/import.png'),'&打开',self)
        importAction.setShortcut('ctrl+o')
        importAction.setStatusTip('打开文件')
        #importAction.triggered.connect(self.openFile)

        menuBar = self.menuBar()
        settingMenu = menuBar.addMenu("文件")
        settingMenu.addAction(settingAction)
        settingMenu.addAction(descAction)
        settingMenu.addAction(aboutAction)
        #self.tabWidget.setCurrentIndex(1)

        self.setWin = None
        self.aboutWin = None
        self.verInfo = getVersionInfStr()

    def openSetWin(self):        
        if not self.setWin:
            self.setWin = SettingWin(self)
            self.setWin.closed.connect(self.onSetWinClose)  
        self.setWin.setVisible(True)
    def openDescWin(self):        
        self.descStr = getAboutStr(self.tabWidget.currentIndex())
        QMessageBox.information(self,"使用说明",self.descStr)

    def openAboutWin(self):        
        QMessageBox.information(self,"版本信息",self.verInfo)

    def initUI(self):
        super().initUI()
    def onSetWinClose(self,flag):        
        if flag:
            self.getPanel(0).updateSetting()
    # 每个QObject及其子类都有一个timerEvent()事件处理器。我们要重新实现这个事件处理器来响应定时器事件。
    def timerEvent(self, e):
        if self.step >= 100:
            self.doAction()
        else:
            self.step = self.step + 1
            self.proBar.setValue(self.step)


if __name__ == "__main__":
    try:       
        initVersionInf(VERSION_PATH)
        initDataTypeCfg()
        initToolCfg()    
        app = QApplication(sys.argv)    
        w = MyMainWin()    
        w.show()
        sys.exit(app.exec_())
    except Exception as e:
        import traceback
        write_log(traceback.format_exc())
        print(traceback.format_exc())
        msg = input("请输入:")
    
    

